Description

Carlisle Rainey

September 22, 2015

alt text

alt text

alt text

alt text

alt text

alt text

First things

Load data and have a quick look

# load data
nominate <- read.csv("data/nominate.csv")

# quick look at data
library(dplyr)
glimpse(nominate)
## Observations: 6,173
## Variables: 6
## $ congress               (int) 100, 100, 100, 100, 100, 100, 100, 100,...
## $ state                  (fctr) USA, ALABAMA, ALABAMA, ALABAMA, ALABAM...
## $ congressional_district (int) 0, 1, 2, 3, 4, 5, 6, 7, 1, 1, 2, 3, 4, ...
## $ party                  (fctr) Republican, Republican, Republican, De...
## $ name                   (fctr) REAGAN, CALLAHAN, DICKINSON, NICHOLS  ...
## $ ideology_score         (dbl) 0.747, 0.358, 0.349, -0.039, -0.203, -0...

Mean of the ideology score

# calculate mean
mean(nominate$ideology_score)
## [1] 0.08724688

Mean of the ideology score for Rs (easy way)

# step-by-step
rep <- nominate$party == "Republican"  # logical vector; TRUE for Rs
head(rep)  # show first six
## [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE
ideology_score_reps <- nominate$ideology_score[rep]  # scores for Rs
head(ideology_score_reps)  # show first six
## [1] 0.747 0.358 0.349 0.253 0.392 0.746
mean(ideology_score_reps)  # mean for Rs
## [1] 0.5454887

Mean of the ideology score for Rs and Ds (quick way)

# all at once
mean(nominate$ideology_score[nominate$party == "Republican"])  # Rs
## [1] 0.5454887
mean(nominate$ideology_score[nominate$party == "Democrat"])  # Rs
## [1] -0.3351859

Mean of the ideology score for Rs and Ds for 100th and 113th Congresses

# all at once
mean(nominate$ideology_score[nominate$party == "Republican" & nominate$congress == 100])  # Rs, 100th
## [1] 0.3165556
mean(nominate$ideology_score[nominate$party == "Republican" & nominate$congress == 113])  # Rs, 113th
## [1] 0.7270549
mean(nominate$ideology_score[nominate$party == "Democrat" & nominate$congress == 100])  # Rs, 100th
## [1] -0.2997308
mean(nominate$ideology_score[nominate$party == "Democrat" & nominate$congress == 113])  # Rs, 113th
## [1] -0.3721133

Standard deviation of the ideology score for Rs and Ds for 100th and 113th Congresses

# all at once
sd(nominate$ideology_score[nominate$party == "Republican" & nominate$congress == 100])  # Rs, 100th
## [1] 0.1712619
sd(nominate$ideology_score[nominate$party == "Republican" & nominate$congress == 113])  # Rs, 113th
## [1] 0.1762492
sd(nominate$ideology_score[nominate$party == "Democrat" & nominate$congress == 100])  # Rs, 100th
## [1] 0.1596674
sd(nominate$ideology_score[nominate$party == "Democrat" & nominate$congress == 113])  # Rs, 113th
## [1] 0.1130054

Mean for both parties and all Congresses

Standard deviation for both parties and all Congresses